//
//  File.js
//  jscsh
//
//  Created by Jonathan Hohle on 1/19/08.
//  Copyright 2008 hohle.net. All rights reserved.
//
//  Todo: wrap these in JSUnit
//
var i = 0; 
print(++i + ': ' + ((File.fnmatch('cat', 'cat') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('cat', 'category') == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('c{at,ub}s', 'cats') == false) ? 'pass' : 'fail'))

print(++i + ': ' + ((File.fnmatch('c?t', 'cat') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('c??t', 'cat') == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('c*', 'cats') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('c*t', 'c/a/b/t') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('ca[a-z]', 'cat') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('ca[^t]', 'cat') == false) ? 'pass' : 'fail'))

print(++i + ': ' + ((File.fnmatch('cat', 'CAT') == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('cat', 'CAT', File.FNM_CASEFOLD) == true) ? 'pass' : 'fail'))

print(++i + ': ' + ((File.fnmatch('?', '/', File.FNM_PATHNAME) == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('*', '/', File.FNM_PATHNAME) == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('[/]', '/', File.FNM_PATHNAME) == false) ? 'pass' : 'fail'))

print(++i + ': ' + ((File.fnmatch('\?', '?') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('\a', 'a') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('\a',   '\a', File.FNM_NOESCAPE) == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('[\?]', '?') == true) ? 'pass' : 'fail'))

print(++i + ': ' + ((File.fnmatch('*', '.profile') == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('*', '.profile', File.FNM_NOESCAPE) == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('.*', '.profile') == true) ? 'pass' : 'fail'))

var rbfiles = '**/*.rb'
print(++i + ': ' + ((File.fnmatch(rbfiles, 'main.rb') == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch(rbfiles, './main.rb') == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch(rbfiles, 'lib/song.rb') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('**.rb', 'main.rb') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('**.rb', './main.rb') == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('**.rb', 'lib/song.rb') == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch('*', 'dave/.profile') == true) ? 'pass' : 'fail'))

var pattern = '*/*'
print(++i + ': ' + ((File.fnmatch(pattern, 'dave/.profile', File.FNM_PATHNAME) == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch(pattern, 'dave/.profile', File.FNM_PATHNAME | File.FNM_DOTMATCH) == true) ? 'pass' : 'fail'))

var pattern = '**/foo'
print(++i + ': ' + ((File.fnmatch(pattern, 'a/b/c/foo', File.FNM_PATHNAME) == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch(pattern, '/a/b/c/foo', File.FNM_PATHNAME) == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch(pattern, 'c:/a/b/c/foo', File.FNM_PATHNAME) == true) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch(pattern, 'a/.b/c/foo', File.FNM_PATHNAME) == false) ? 'pass' : 'fail'))
print(++i + ': ' + ((File.fnmatch(pattern, 'a/.b/c/foo', File.FNM_PATHNAME | File.FNM_DOTMATCH) == true) ? 'pass' : 'fail'))

rbfiles = undefined
pattern = undefined
pattern = undefined